package chpt06;

import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo04 {

	public static void main(String[] args) {
		Set<StudentV1> students = 
				new TreeSet<>(new Comparator<StudentV1>(){
			public int compare(StudentV1 s1,StudentV1 s2) {
				/* 按年龄升序排列
				return s1.getsAge() - s2.getsAge(); */
				/* 按年龄降序排列
				return s2.getsAge() - s1.getsAge(); */
				// 按姓名字典逆序排序
				return -1*s1.getsName().compareTo(s2.getsName());
			}
		});
		students.add(new StudentV1("abx",18));
		students.add(new StudentV1("abc",20));
		students.add(new StudentV1("bax",17));

        Iterator<StudentV1> iter = students.iterator();
        while(iter.hasNext()) {
        	System.out.println(iter.next());
        }  
	}
}
